/**
 * LocalTimeDeserializer.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2015年1月20日
 */
package com.pshare.framework.databind;

import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.node.TextNode;

/**
 * json to localdate
 */
public class LocalTimeDeserializer extends JsonDeserializer<LocalTime> {
	
	@Override
	public LocalTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
			JsonProcessingException {

		ObjectCodec oc = jp.getCodec();
		TextNode node = (TextNode) oc.readTree(jp);
		String dateString = node.textValue();

		Instant instant = Instant.parse(dateString);
		LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
		return dateTime.toLocalTime();
	}

}
